package com.directv.z8training.ex8;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;


/**
 * @author HieuLT8
 *
 */
public class RunDemo {
	
	public static void main(String[] args) {
		List<Person1> list = new ArrayList<Person1>();
		Person1 p1 = new Person1("An", "HCM", 20);
		Person1 p2 = new Person1("Binh", "HCM", 5);
		Person1 p3 = new Person1("Tuan", "HCM", 6);
		Person1 p4 = new Person1("Chau", "HCM", 11);
		Person1 p5 = new Person1("Thai", "HCM", 20);
		Person1 p6 = new Person1("Dung", "HCM", 21);
		Person1 p7 = new Person1("Hoang", "HCM", 22);
		Person1 p8 = new Person1("Kiet", "HCM", 23);
		Person1 p9 = new Person1("Lan", "HCM", 24);
		Person1 p10 = new Person1("Tien", "HCM", 5);
		Person1 p11 = new Person1("Bich", "HCM", 6);
		Person1 p12 = new Person1("Minh", "HCM", 10);
		Person1 p13 = new Person1("An", "HCM", 20);
		Person1 p14 = new Person1("Binh", "HCM", 5);
		Person1 p15 = new Person1("Tuan", "HCM", 6);
		Person1 p16 = new Person1("Chau", "HCM", 11);
		Person1 p17 = new Person1("Thai", "HCM", 20);
		Person1 p18 = new Person1("Dung", "HCM", 21);
		Person1 p19 = new Person1("Hoang", "HCM", 22);
		Person1 p20 = new Person1("Kiet", "HCM", 23);
		Person1 p21 = new Person1("Lan", "HCM", 24);
		Person1 p22 = new Person1("Tien", "HCM", 5);
		Person1 p23 = new Person1("Bich", "HCM", 6);
		Person1 p24 = new Person1("Minh", "HCM", 10);
		Person1 p25 = new Person1("Toan", "HCM", 10);
		
		list.add(p1);
		list.add(p2);
		list.add(p3);
		list.add(p4);
		list.add(p5);
		list.add(p6);
		list.add(p7);
		list.add(p8);
		list.add(p9);
		list.add(p10);
		list.add(p11);
		list.add(p12);
		list.add(p13);
		list.add(p14);
		list.add(p15);
		list.add(p16);
		list.add(p17);
		list.add(p18);
		list.add(p19);
		list.add(p20);
		list.add(p21);
		list.add(p22);
		list.add(p23);
		list.add(p24);
		
		Iterator<Person1> itr = list.iterator();
		while (itr.hasNext()) {
			Person1 p = itr.next();
			System.out.println("Name: " + p.getName() + "-----" + "Age: " + p.getAge());
		}
		ListIterator<Person1> litr = list.listIterator();
		System.out.println("List Iterator: ");
		while (litr.hasNext()) {
			Person1 p = litr.next();
			System.out.println("Name: " + p.getName() + "-----" + "Age: " + p.getAge());
		}
		litr.add(p25);

		System.out.println("List Iterator Last to First: ");
		while (litr.hasPrevious()) {
			Person1 p = litr.previous();
			System.out.println("Name: " + p.getName() + "-----" + "Age: " + p.getAge());
		}
		Collections.sort(list, new CompareName());
		System.out.println("Sort Name");
		for (Person1 p : list) {
			System.out.println("Name: " + p.getName() + "======" + "Age: "
					+ p.getAge());
		}
	}
}
